package org.scirp.ijmis.dao.journal.impl;

import java.util.List;

import org.scirp.ijmis.dao.base.impl.BaseDAOImpl;
import org.scirp.ijmis.dao.journal.IJournalDAO;
import org.scirp.ijmis.po.journal.Journal;

public class JournalDAOImpl extends BaseDAOImpl<Journal> implements IJournalDAO {

	private static final String className = JournalDAOImpl.class.toString();

	public List<Journal> selectAll() {

		String hql = "from Journal where pid in(select journal.pid from ParameterOfJournal where paperSystemIsAvailable='true') order by pid desc";
		return super.ExecuteQuery(hql, className + "-->selectAll");
	}
	public List<Journal> selectAllJournal() {

		String hql = "from Journal  order by pid desc";
		return super.ExecuteQuery(hql, className + "-->selectAll");
	}
	public List<Journal> selectAllJournal(String orderProperty) {
		String hql = "from Journal  order by "+orderProperty;
		return super.ExecuteQuery(hql, className + "-->selectAll");
	}
	public Journal selectById(long id) {

		return (Journal) super.selectById(id, className + "-->selectById");
	}

	public Journal deleteJournal(Journal journal) {
		return super.deleteObject(journal, className + "-->deleteJournal");
	}
	public List<String> selectPersonByName(String leaderName){
		String hql = "select distinct responsiblePerson from Journal where leader='"+leaderName+"' and responsiblePerson<>'"+leaderName+"' and pid in(select journal.pid from ParameterOfJournal where paperSystemIsAvailable='true')" ;
		return selectProperty(hql,null, 0, 0, className + "-->selectAll(String orderProperty)");
	}
	public long saveJournal(Journal journal) {
		return super.saveObject(journal, className + "-->saveJournal");
	}

	public List<Journal> selectAll(String orderProperty) {
		String hql = "from Journal where pid in(select journal.pid from ParameterOfJournal where paperSystemIsAvailable='true') order by " + orderProperty;
		return super.ExecuteQuery(hql, className + "-->selectAll(String orderProperty)");
	}

	public boolean updateJournal(Journal journal) {
		return super.updateObject(journal, className + "-->updateJournal");
	}

	public List<Journal> selectAllOrderByShortEnglishName() {
		String hql = "from Journal where pid in(select journal.pid from ParameterOfJournal where paperSystemIsAvailable='true') order by shortEnglishName";
		return super.ExecuteQuery(hql, className + "-->selectAllOrderByPerson()");
	}

	public List<Journal> selectAllOrderByPerson() {
		String hql = "from Journal where pid in(select journal.pid from ParameterOfJournal where paperSystemIsAvailable='true') order by leader,shortEnglishName";
		return super.ExecuteQuery(hql, className + "-->selectAllOrderByPerson()");
	}
	@Override
	public List<Journal> selectJournalNameAndLeader() {
		String hql= " from Journal where leader is not null order by leader,responsibleperson,shortenglishname";
		return super.ExecuteQuery(hql, className + "-->selectJournalNameAndLeader()");
	}
}
